package com.ruoyi.scsystem.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.scsystem.domain.SysProjectCategory;
import com.ruoyi.scsystem.mapper.SysApplicationMapper;
import com.ruoyi.scsystem.domain.SysApplication;
import com.ruoyi.scsystem.service.ISysApplicationService;

/**
 * 学分审核Service业务层处理
 * 
 * @author cai
 * @date 2022-09-19
 */
@Service
public class SysApplicationServiceImpl implements ISysApplicationService 
{
    @Autowired
    private SysApplicationMapper sysApplicationMapper;

    /**
     * 查询学分审核
     * 
     * @param appId 学分审核主键
     * @return 学分审核
     */
    @Override
    public SysApplication selectSysApplicationByAppId(String appId)
    {
        return sysApplicationMapper.selectSysApplicationByAppId(appId);
    }

    /**
     * 查询学分审核列表
     * 
     * @param sysApplication 学分审核
     * @return 学分审核
     */
    @Override
    public List<SysApplication> selectSysApplicationList(SysApplication sysApplication)
    {
        return sysApplicationMapper.selectSysApplicationList(sysApplication);
    }

    /**
     * 新增学分审核
     * 
     * @param sysApplication 学分审核
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysApplication(SysApplication sysApplication)
    {
        int rows = sysApplicationMapper.insertSysApplication(sysApplication);
        insertSysProjectCategory(sysApplication);
        return rows;
    }

    /**
     * 修改学分审核
     * 
     * @param sysApplication 学分审核
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysApplication(SysApplication sysApplication)
    {
        sysApplicationMapper.deleteSysProjectCategoryByCatId(sysApplication.getAppId());
        insertSysProjectCategory(sysApplication);
        return sysApplicationMapper.updateSysApplication(sysApplication);
    }

    /**
     * 批量删除学分审核
     * 
     * @param appIds 需要删除的学分审核主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysApplicationByAppIds(String[] appIds)
    {
        sysApplicationMapper.deleteSysProjectCategoryByCatIds(appIds);
        return sysApplicationMapper.deleteSysApplicationByAppIds(appIds);
    }

    /**
     * 删除学分审核信息
     * 
     * @param appId 学分审核主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysApplicationByAppId(String appId)
    {
        sysApplicationMapper.deleteSysProjectCategoryByCatId(appId);
        return sysApplicationMapper.deleteSysApplicationByAppId(appId);
    }

    /**
     * 新增项目管理信息
     * 
     * @param sysApplication 学分审核对象
     */
    public void insertSysProjectCategory(SysApplication sysApplication)
    {
        List<SysProjectCategory> sysProjectCategoryList = sysApplication.getSysProjectCategoryList();
        String appId = sysApplication.getAppId();
        if (StringUtils.isNotNull(sysProjectCategoryList))
        {
            List<SysProjectCategory> list = new ArrayList<SysProjectCategory>();
            for (SysProjectCategory sysProjectCategory : sysProjectCategoryList)
            {
                sysProjectCategory.setCatId(appId);
                list.add(sysProjectCategory);
            }
            if (list.size() > 0)
            {
                sysApplicationMapper.batchSysProjectCategory(list);
            }
        }
    }
}
